﻿@{
    Layout = null;
}

<!DOCTYPE html>

<html class="x-admin-sm">
<head>
    <meta name="viewport" content="width=device-width" />
    <meta name="viewport" content="width=device-width" />
    <meta charset="UTF-8">
    <title>数据账套</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
    <link href="~/X-admin/css/font.css" rel="stylesheet" />
    <script src="~/X-admin/lib/layui/layui.js"></script>
    <link href="~/X-admin/css/xadmin.css" rel="stylesheet" />
    <script src="~/X-admin/js/jquery.min.js"></script>
    <script src="~/X-admin/js/xadmin.js"></script>
    <script src="~/js/framework/sysframework.js"></script>
    <script src="~/js/framework/commonjs.js"></script>

</head>
<body>
    <ul lay-bar="disabled" class="mWebBanner">
        <li class="layui-nav-item" style="float:left;">
            <button type="button" name="btn_update" onclick="saveData()" class="buttonCss">
                <i class="layui-icon" style="margin-right:3px">&#xe697;</i>保存
            </button>
        </li>
        <li class="layui-nav-item" style="float:left;margin-left:3%">
            <button type="button" onclick="closeWin()" class="buttonCss">
                <i class="layui-icon" style="margin-right:3px">&#x1007;</i>取消
            </button>
        </li>
    </ul>
    <div style="margin: 20px; border: 1px solid #dbdbdb;padding:15px">

        <form id="AddForm" class="layui-form layui-col-space5">

            <div class="layui-form-item">

                <label for="L_email" class="layui-form-label">
                    账套名称
                </label>
                <div class="layui-input-inline">
                    <input type="text" id="customName" name="customName" required="" autocomplete="off" class="layui-input">
                    <input type="hidden" id="id" name="Id">
                </div>
            </div>
            <div class="layui-form-item">
                <label for="L_email" class="layui-form-label">
                    IP地址
                </label>
                <div class="layui-input-inline">
                    <input type="text" id="serverIp" name="serverIp" required="" autocomplete="off" class="layui-input">
                </div>
                <label for="L_email" class="layui-form-label">
                    数据库名
                </label>
                <div class="layui-input-inline">
                    <input type="text" id="baseName" name="baseName" required="" autocomplete="off" class="layui-input">

                </div>
            </div>

            <div class="layui-form-item">
                <label for="L_email" class="layui-form-label">
                    登录账号
                </label>
                <div class="layui-input-inline">
                    <input type="text" id="logid" name="logid" required="" autocomplete="off" class="layui-input">
                </div>
                <label for="L_email" class="layui-form-label">
                    登录密码
                </label>
                <div class="layui-input-inline">
                    <input type="text" id="pwd" name="pwd" required="" autocomplete="off" class="layui-input">

                </div>
            </div>


            <div class="layui-form-item">
                <label for="L_email" class="layui-form-label">
                    是否默认
                </label>
                <div class="layui-input-inline">
                    <select name="isDefault" id="isDefault"  ></select>
                </div>
                <label for="L_email" class="layui-form-label">
                    是否启用
                </label>
                <div class="layui-input-inline">
                    <select name="status" id="status" ></select>
                </div>

            </div>
        </form>

    </div>
</body>
</html>
<script type="text/javascript">
    $(function () {
        var dataId = getUrlVariable("dataId");
        DictionaryDropDown("ct", "isDefault", "");
        DictionaryDropDown("ct", "status", "");
        if (dataId != "0") {
            $("input[ name='Id']").val(dataId);
            loadData(dataId);
        }

    });

    /**
    保存数据
    **/ 
    function saveData() {
        $.ajax({
            url: "../System/SaveBaseData",
            data: { datas: JSON.stringify(FormToJson("AddForm")) },
            dataType: "json",
            type: "POST",
            success: function (data) {
                if (data.result) {
                    var id = $("input[ name='id']").val();
                    var msg = "信息修改成功";
                    if (id == "0" || id == "") {
                        msg = "信息添加成功";
                    }
                    layer.alert(msg, { icon: 6 }, function () {
                        // 获得frame索引
                        var index = parent.layer.getFrameIndex(window.name);
                        //关闭当前frame
                        parent.layer.close(index);
                    });
                } else {
                    layer.msg(data.message);
                }
            }
        });
    }

    //加载数据信息
    function loadData(dataId) {
        $.ajax({
            url: "../System/getCustomBaseByCode",
            type: "post",
            data: { dataId: dataId },
            success: function (data) {
                if (data.result) {

                    $.each(data.data[0], function (name, value) {
                        if (name == "isDefault" || name == "status") {
                            $("#" + name + "  option[value='" + value + "'] ").attr("selected", true)
                        } else {
                            $("input[ name='" + name + "']").val(value);
                        }
                    
                    });
                  //  $("#parValue").html(data.Data[0]["parValue"]);
                  
                
                }
            }
        });

    }
</script>